package
{
	import com.learnosity.extendotext.StyleSheet;
	import com.learnosity.extendotext.RuleSet;
	import flash.display.Sprite;
	import flash.events.*;
	import flash.net.*;
	import flash.text.engine.ElementFormat;
	
	public class TestStyles extends Sprite
	{
		private var testContent:String = "";
		
		private	var ss:StyleSheet = new StyleSheet();
		
		public function TestStyles()
		{
					
			//Load external stylesheet
			var loader:URLLoader = new URLLoader();
	        var request:URLRequest = new URLRequest("default.css");
	        loader.addEventListener(Event.COMPLETE, completeHandler);
	        
            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
		}

		private function completeHandler(event:Event):void {
            var loader:URLLoader = URLLoader(event.target);
            trace("completeHandler: " + loader.data);
    		
    		ss.content = loader.data;
    		
    		
    		testMatching();
        }

  		/**
  		 * Test function which checks matches for a known stylesheet
  		 */
		private function testMatching():void
		{
			var matched:Vector.<RuleSet> = ss.findRules('b');
			trace( matched.length == 2?'OK':'Fail');

			matched = ss.findRules('sup');
			trace( matched.length == 1?'OK':'Fail');

			matched = ss.findRules('strong');
			trace( matched.length == 1?'OK':'Fail');

			matched = ss.findRules('.myClass');
			trace( matched.length == 1?'OK':'Fail');
		
		
			var format:ElementFormat = ss.getFormattingObject(matched);
		
		}



	}
}